package com.base.controller;

import com.base.annotation.HasPermission;
import com.base.common.AjaxResult;
import com.base.common.BaseController;
import com.base.common.TableDataInfo;
import com.base.domain.SysUser;
import com.base.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author gxd
 * @since 2025/6/6
 */
@Slf4j
@RestController
@RequestMapping("/user")
@Api(tags = "用户信息")
public class SysUserController extends BaseController {

    @Autowired
    private SysUserService userService;

    @ApiOperation("分页列表-用户列表")
    @PostMapping("/pageList")
    @HasPermission("system:user:list")
    public TableDataInfo pageList(@ApiParam(value = "用户查询条件") SysUser user) {
        startPage(user.getPageNum(), user.getPageSize());
        List<SysUser> userList = userService.pageList(user);
        return getDataTable(userList);
    }

    @ApiOperation("详情信息-根据id获取用户详情信息")
    @ApiImplicitParam(name = "id", value = "用户Id", required = true, dataType = "Long", paramType = "path")
    @GetMapping("/getById/{id}")
    public AjaxResult getById(@PathVariable Long id) {
        return success(userService.getInfoById(id));
    }

    @ApiOperation("添加或修改-用户信息")
    @PostMapping("/addOrEdit")
    public AjaxResult addOrEdit(@ApiParam(value = "用户实体", required = true) @Valid @RequestBody SysUser user) {
        return success(userService.addOrEdit(user));
    }

    @ApiOperation("删除-用户信息（支持批量）")
    @ApiImplicitParam(name = "ids", value = "用户id（多个需逗号分隔）", required = true, allowMultiple = true, dataType = "String", paramType = "path")
    @DeleteMapping("/removeById")
    public AjaxResult removeById(@RequestParam("ids") String ids) {
        return toAjax(userService.deleteByIds(ids));
    }

    @ApiOperation("获取用户信息-带翻译（deptMc、sexMc）")
    @PostMapping("/selectUserMcList")
    public TableDataInfo selectUserMcList(@RequestBody SysUser user) {
        startPage(user.getPageNum(), user.getPageSize());
        return getDataTable(userService.selectUserMcList(user));
    }
}
